//
//  YXSettingItemController.m
//  彩票
//
//  Created by mac on 15-4-1.
//  Copyright (c) 2015年 mac. All rights reserved.
//

#import "YXSettingItemController.h"
#import "YXSettingItem.h"

@interface YXSettingItemController () 

@property (nonatomic, strong) NSMutableArray *modleM;

@end

@implementation YXSettingItemController

- (instancetype)init
{
    
    return [self initWithStyle:UITableViewStyleGrouped];
}

//- (instancetype)initWithStyle:(UITableViewStyle)style
//{
//    if (self = [super initWithStyle:UITableViewStyleGrouped]) {
//        
//    }
//    return self;
//}

- (NSMutableArray *)modleM
{
    if (!_modleM) {
        _modleM = [NSMutableArray array];
    }
    return _modleM;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // 初始化右边按钮
    UIBarButtonItem *itemBtn = [[UIBarButtonItem alloc] initWithTitle:@"常规问题" style:UIBarButtonItemStylePlain target:self action:@selector(itemBtnClick)];
    self.navigationItem.rightBarButtonItem = itemBtn;
    self.navigationItem.rightBarButtonItem.tintColor = [UIColor whiteColor];
    [self setupGoup0];
    [self setupGoup1];
    [self setupGoup2];
    
 
}
- (void)setupGoup0
{
//    NSArray *array = [NSArray array];
    YXSettingItem *item0 = [YXSettingItem initWithImage:@"RedeemCode" andLable:@"使用兑换码"];
    NSArray *array = @[item0];
    [self.modleM addObject:array];
    
    
}
- (void)setupGoup2
{
//    NSArray *array = [NSArray array];
//    __block UITableViewController *vc = self;
    YXSettingItem *update = [YXSettingItem initWithImage:@"MoreUpdate" andLable:@"检查新版本"];
//    __weak typeof(self) weakSelf = self;
//    UIAlertView *alertVIew =[[UIAlertView alloc] initWithTitle:@"检测版本" message:@"没有" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    update.option = ^{
    
       [[[UIAlertView alloc] initWithTitle:@"检测版本" message:@"没有" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil] show];
        
    
//        [alertVIew show];
    };
    
    UIAlertView *alertView2 = [[UIAlertView alloc] initWithTitle:@"分享" message:@"分享到微信" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    YXSettingItem *share = [YXSettingItem initWithImage:@"MoreShare" andLable:@"分享"];
    share.option = ^{
        [alertView2 show];
      
    };
    
    YXSettingItem *nettease = [YXSettingItem initWithImage:@"MoreNetease" andLable:@"产品推荐"];
    YXSettingItem *about = [YXSettingItem initWithImage:@"MoreAbout" andLable:@"关于"];
    NSArray *array = @[update, share, nettease, about];
    [self.modleM addObject:array];
}
- (void)setupGoup1
{
//    NSArray *array = [NSArray array];
    YXSettingItem *message = [YXSettingItem initWithImage:@"MorePush"andLable:@"推送和提醒"];
    YXSettingItem *shake = [YXSettingItem initWithImage:@"more_homeshake" andLable:@"使用摇一摇机选"];
    YXSettingItem *voice = [YXSettingItem initWithImage:@"sound_Effect" andLable:@"声音效果"];
    YXSettingItem *assistant = [YXSettingItem initWithImage:@"More_LotteryRecommend" andLable:@"购彩小助手"];
    NSArray *array = @[message, shake, voice, assistant];
    [self.modleM addObject:array];

}


#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return self.modleM.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // 取出对应的组
    NSArray *array = self.modleM[section];
    
    
    return array.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *ID = @"cell_";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
}
     NSArray *array = self.modleM[indexPath.section];
    YXSettingItem *modle = array[indexPath.row];
    cell.imageView.image = [UIImage imageNamed:modle.icon];
    cell.textLabel.text = modle.lable;

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    NSArray *array = self.modleM[indexPath.section];
    YXSettingItem *modle1 = array[indexPath.row];
    NSLog(@"%@", modle1.lable);
    NSLog(@"%zd==%zd",indexPath.section,indexPath.row);
    if (modle1.option) {
        modle1.option();
        return;
    }
//       [[[UIAlertView alloc] initWithTitle:@"分享" message:@"分享到微信" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil] show];
}

- (void)itemBtnClick
{
    UIViewController *vc =[[UIViewController alloc] init];
    vc.view.backgroundColor = [UIColor whiteColor];
    [self.navigationController pushViewController:vc animated:YES];
}

//- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
//    if (buttonIndex == 1) {
//        NSLog(@"点击了");
//    }
//}
//- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
//
//  NSLog(@"%s", __FUNCTION__);
//}
@end
